package app.fugema.shop.main.home.adapter;

import android.view.View;
import android.view.ViewGroup;

import com.base.common.utils.DensityUtil;
import com.base.common.view.adapter.ada.BaseRVAdapter;
import com.base.common.view.adapter.ada.SingleRecyclerAdapter;
import com.base.common.view.adapter.connector.BaseViewHolder;
import app.fugema.shop.R;
import app.fugema.shop.databinding.HomeSearchGoodsItemBinding;
import app.fugema.shop.main.goods.model.CateGoodsPageBean;
import app.fugema.shop.main.goods.view.GoodsDetailActivity;
import app.fugema.shop.main.home.model.SearchGoodsBean;

public class HomeSearchGoodsAdapter extends SingleRecyclerAdapter<CateGoodsPageBean.ProductBean, HomeSearchGoodsItemBinding> {

    @Override
    public int getLayoutId() {
        return R.layout.home_search_goods_item;
    }

    @Override
    public void onBindViewHolder(HomeSearchGoodsItemBinding binding, int position, BaseViewHolder viewHolder, CateGoodsPageBean.ProductBean bean) {
        super.onBindViewHolder(binding, position, viewHolder, bean);
        if (binding.rclItemView.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) binding.rclItemView.getLayoutParams();
            if (position % 2 == 0) {
                marginLayoutParams.leftMargin = DensityUtil.getDimens(R.dimen.dp_0);
            } else {
                marginLayoutParams.leftMargin = DensityUtil.getDimens(R.dimen.dp_4);
            }
            binding.rclItemView.setLayoutParams(marginLayoutParams);
        }
    }

    @Override
    public void onItemClick(View view, BaseRVAdapter adapter, int onclickType, int position, CateGoodsPageBean.ProductBean bean) {
        super.onItemClick(view, adapter, onclickType, position, bean);
        GoodsDetailActivity.start(view.getContext(), bean.getProductId());
    }
}
